Python 3
import pandas as pdcorona_df = pd.read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/05-27-2020.csv")by_country = corona_df.groupby('Country_Region').sum()[['Confirmed', 'Deaths', 'Recovered', 'Active']]cdf = by_country.nlargest(15,'Confirmed')[['Confirmed']]| Confirmed | |
|---|---|
| Country_Region | |
| US | 1699176 |
| Brazil | 411821 |
| Russia | 370680 |
| United Kingdom | 268619 |
| Spain | 236259 |
| Italy | 231139 |
| France | 183038 |
| Germany | 181524 |
| Turkey | 159797 |
| India | 158086 |
| Iran | 141591 |
| Peru | 135905 |
| Canada | 88989 |
| China | 84106 |
| Chile | 82289 |
def find_top_confirmed(n=15): import pandas as pd corona_df = pd.read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/05-27-2020.csv") by_country = corona_df.groupby('Country_Region').sum()[['Confirmed', 'Deaths', 'Recovered', 'Active']] cdf = by_country.nlargest(n,'Confirmed')[['Confirmed']] return cdffind_top_confirmed(10) | Confirmed | |
|---|---|
| Country_Region | |
| US | 1699176 |
| Brazil | 411821 |
| Russia | 370680 |
| United Kingdom | 268619 |
| Spain | 236259 |
| Italy | 231139 |
| France | 183038 |
| Germany | 181524 |
| Turkey | 159797 |
| India | 158086 |
import pandas as pdcorona_df = pd.read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/05-27-2020.csv")corona_df.head(2)| FIPS | Admin2 | Province_State | Country_Region | Last_Update | Lat | Long_ | Confirmed | Deaths | Recovered | Active | Combined_Key | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 45001.0 | Abbeville | South Carolina | US | 2020-05-28 02:32:31 | 34.223334 | -82.461707 | 35 | 0 | 0 | 35 | Abbeville, South Carolina, US |
| 1 | 22001.0 | Acadia | Louisiana | US | 2020-05-28 02:32:31 | 30.295065 | -92.414197 | 397 | 22 | 0 | 375 | Acadia, Louisiana, US |
corona_df.nlargest(15,'Confirmed')| FIPS | Admin2 | Province_State | Country_Region | Last_Update | Lat | Long_ | Confirmed | Deaths | Recovered | Active | Combined_Key | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 3368 | NaN | NaN | NaN | Russia | 2020-05-28 02:32:31 | 61.524010 | 105.318756 | 370680 | 3968 | 142208 | 224504 | Russia |
| 3404 | NaN | NaN | NaN | United Kingdom | 2020-05-28 02:32:31 | 55.378100 | -3.436000 | 267240 | 37460 | 0 | 229780 | United Kingdom |
| 1942 | 36061.0 | New York City | New York | US | 2020-05-28 02:32:31 | 40.767273 | -73.971526 | 199968 | 21362 | 0 | 178606 | New York City, New York, US |
| 3293 | NaN | NaN | NaN | France | 2020-05-28 02:32:31 | 46.227600 | 2.213700 | 180044 | 28546 | 64503 | 86995 | France |
| 3400 | NaN | NaN | NaN | Turkey | 2020-05-28 02:32:31 | 38.963700 | 35.243300 | 159797 | 4431 | 122793 | 32573 | Turkey |
| 3309 | NaN | NaN | NaN | India | 2020-05-28 02:32:31 | 20.593684 | 78.962880 | 158086 | 4534 | 67749 | 85803 | India |
| 3311 | NaN | NaN | NaN | Iran | 2020-05-28 02:32:31 | 32.427908 | 53.688046 | 141591 | 7564 | 111176 | 22851 | Iran |
| 3362 | NaN | NaN | NaN | Peru | 2020-05-28 02:32:31 | -9.190000 | -75.015200 | 135905 | 3983 | 56169 | 75753 | Peru |
| 3191 | NaN | NaN | Sao Paulo | Brazil | 2020-05-28 02:32:31 | -23.550500 | -46.633300 | 89483 | 6712 | 0 | 82771 | Sao Paulo, Brazil |
| 3116 | NaN | NaN | Lombardia | Italy | 2020-05-28 02:32:31 | 45.466794 | 9.190347 | 87801 | 15954 | 47810 | 24037 | Lombardia, Italy |
| 3375 | NaN | NaN | NaN | Saudi Arabia | 2020-05-28 02:32:31 | 23.885942 | 45.079162 | 78541 | 425 | 51022 | 27094 | Saudi Arabia |
| 600 | 17031.0 | Cook | Illinois | US | 2020-05-28 02:32:31 | 41.841448 | -87.816588 | 74521 | 3455 | 0 | 71066 | Cook, Illinois, US |
| 3104 | NaN | NaN | Hubei | China | 2020-05-28 02:32:31 | 30.975600 | 112.270700 | 68135 | 4512 | 63618 | 5 | Hubei, China |
| 3120 | NaN | NaN | Madrid | Spain | 2020-05-28 02:32:31 | 40.416800 | -3.703800 | 68066 | 8691 | 40736 | 18639 | Madrid, Spain |
| 3132 | NaN | NaN | Metropolitana | Chile | 2020-05-28 02:32:31 | -33.437600 | -70.650500 | 66011 | 595 | 0 | 65416 | Metropolitana, Chile |
by_country = corona_df.groupby('Country_Region').sum()[['Confirmed', 'Deaths', 'Recovered', 'Active']]by_country.nlargest(15,'Confirmed')[['Confirmed']]| Confirmed | |
|---|---|
| Country_Region | |
| US | 1699176 |
| Brazil | 411821 |
| Russia | 370680 |
| United Kingdom | 268619 |
| Spain | 236259 |
| Italy | 231139 |
| France | 183038 |
| Germany | 181524 |
| Turkey | 159797 |
| India | 158086 |
| Iran | 141591 |
| Peru | 135905 |
| Canada | 88989 |
| China | 84106 |
| Chile | 82289 |
import folium# 2m = folium.Map(location = [32.223334, -82.461707], tiles = "Stamen toner", zoom_start = 8)import foliumfolium.Circle(location = [34.223334, -82.461707], radius = 10000, color = "red", fill = True, popup = 'confirmed {}'.format(20)).add_to(m)<folium.vector_layers.Circle at 0x245f6361128>
def circle_maker(x): folium.Circle(location = [x[0], x[1]], radius = float(x[2])*10, popup = '{}\nConfirmed Cases: {}'.format(x[3], x[2])).add_to(m)corona_df[['Lat', 'Long_', 'Confirmed', 'Combined_Key']].apply(lambda x: circle_maker(x), axis = 1)--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-62-680dc6aac850> in <module>() ----> 1 corona_df[['Lat', 'Long_', 'Confirmed', 'Combined_Key']].apply(lambda x: circle_maker(x), axis = 1) C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in apply(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds) 6002 args=args, 6003 kwds=kwds) -> 6004 return op.get_result() 6005 6006 def applymap(self, func): C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\apply.py in get_result(self) 140 return self.apply_raw() 141 --> 142 return self.apply_standard() 143 144 def apply_empty_result(self): C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\apply.py in apply_standard(self) 246 247 # compute the result using the series generator --> 248 self.apply_series_generator() 249 250 # wrap results C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\apply.py in apply_series_generator(self) 275 try: 276 for i, v in enumerate(series_gen): --> 277 results[i] = self.f(v) 278 keys.append(v.name) 279 except Exception as e: <ipython-input-62-680dc6aac850> in <lambda>(x) ----> 1 corona_df[['Lat', 'Long_', 'Confirmed', 'Combined_Key']].apply(lambda x: circle_maker(x), axis = 1) <ipython-input-61-47134ed06616> in circle_maker(x) 2 folium.Circle(location = [x[0], x[1]], 3 radius = float(x[2])*10, ----> 4 popup = '{}\nConfirmed Cases: {}'.format(x[3], x[2])).add_to(m) C:\ProgramData\Anaconda3\lib\site-packages\folium\vector_layers.py in __init__(self, location, radius, popup, tooltip, **kwargs) 265 266 def __init__(self, location, radius, popup=None, tooltip=None, **kwargs): --> 267 super(Circle, self).__init__(location, popup=popup, tooltip=tooltip) 268 self._name = 'circle' 269 self.options = path_options(line=False, radius=radius, **kwargs) C:\ProgramData\Anaconda3\lib\site-packages\folium\map.py in __init__(self, location, popup, tooltip, icon, draggable, **kwargs) 275 super(Marker, self).__init__() 276 self._name = 'Marker' --> 277 self.location = validate_location(location) 278 self.options = parse_options( 279 draggable=draggable or None, C:\ProgramData\Anaconda3\lib\site-packages\folium\utilities.py in validate_location(location) 63 .format(coord, type(coord))) 64 if math.isnan(float(coord)): ---> 65 raise ValueError('Location values cannot contain NaNs.') 66 return [float(x) for x in coords] 67 ValueError: ('Location values cannot contain NaNs.', 'occurred at index 867')
m